
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>组列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/lib/layui/css/layui.css">
    <script src="/static/lib/layui/layui.js"></script>
</head>
<body>
<h1 style="margin-top: 20px">组</h1>
 <hr class="layui-border-blue">
<form class="layui-form" action="" id="searchForm">
    <div class="layui-form-item">
    <br>
        <div class="layui-inline" style="margin-left:1100px">
            <div class="layui-input-inline">
                <input type="tel" name="ispay" id="ispay" autocomplete="off" class="layui-input" placeholder="过滤">
            </div>
        </div>
        <div class="layui-inline">
            <button type="submit" class="layui-btn layui-btn-normal">搜索&nbsp;<i class="layui-icon layui-icon-search" ></i></button>
        </div>
    </div>
    </div>
</form>

<table class="layui-hide" id="test" lay-filter="test" ></table>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container" style="float: right">
          <button class="layui-btn layui-btn-normal  layui-btn-sm data-add-btn" lay-event="add"> <i class="layui-icon" >&#xe654;</i>创建组</button>
         <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="getCheckLength"><i class="layui-icon">&#xe640;</i>删除组</button>
    </div>
</script>
<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-sm  layui-btn-normal" lay-event="more">管理成员<i class="layui-icon layui-icon-down"></i></a>
</script>

<script>
    var $ ,layer,table,dropdown;
    layui.use(['table','form','dropdown'], function(){
        table=layui.table;
        var form = layui.form;
         $=layui.jquery;
        layer=layui.layer;
        var dropdown = layui.dropdown;


        table.render({
            elem: '#test'
            ,url:'http://127.0.0.1:8000/zgh0381/group_json/'
            ,toolbar: '#toolbarDemo'
            ,title: '组列表'
            ,totalRow: true
            ,cols: [
                [{type: 'checkbox', fixed: 'left'}
                 ,{field:'name', title:'名称', width:100, fixed: 'left'}
                 ,{field:'description', title:'描述', width:200}
                  ,{field:'id', title:'组标识', width:300}
                  ,{title:'Actions', width:200, align:'center', toolbar: '#barDemo'}

            ]
            ]
            ,page: true
            ,limit:10
            ,limits:[10,11,12,13]
            ,id:'orderTable'
        });


        //工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('选中了：'+ data.length + ' 个');
                    break;
                case 'add':
                   parent.layer.open({
                        type: 2
                        ,offset:'auto'
                        ,title:'创建组'
                        ,content:'/zgh0381/groupcreate/'
                        ,area:['1000px','700px']
                        ,btn:'关闭'
                        ,btnAlign:'c'
                        ,yes:function () {
                           parent.layer.closeAll();
                        }
                        ,end:function() {
                               location.reload();
                            }
                    });
                    break;
            };
        });

        //监听工具条
        table.on('tool(test)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
             var data = obj.data;
             if(layEvent === 'detail'){
              layer.msg('查看操作');
            } else if(layEvent === 'more'){
              //下拉菜单
                dropdown.render({
                elem: this //触发事件的 DOM 对象
                ,show: true //外部事件触发即显示
                ,data: [{
                  title: '删除组'
                  ,id: 'del_group'
                },{
                    title:'编辑组'
                     ,id:'edit_gruop'
                    },{
                     title:'管理成员'
                     ,id:'manage_group'
                    }
                ]
                ,click: function(menudata){
                  if(menudata.id === 'del_group'){
                    layer.confirm('真的删除么？', function(index){
                      obj.del(); //删除对应行（tr）的DOM结构
                      layer.close(index);
                      //向服务端发送删除指令
                         $.ajax({
                                            url:"/zgh0381/group_delete/"+ data.id ,
                                            type:"GET",
                                             beforeSend: function (xhr, settings) {
                                            xhr.setRequestHeader("X-CSRFToken", "{{ csrf_token }}");
                                          },
                                            success:function(result) {
                                                    if(result.res == 1){
                                                       layui.use(['notice'], function () {
                                                        var notice = layui.notice; // 允许别名 toastr

                                                        // 初始化配置，同一样式只需要配置一次，非必须初始化，有默认配置
                                                        notice.options = {
                                                            closeButton:true,//显示关闭按钮
                                                            debug:false,//启用debug
                                                            positionClass:"toast-top-right",//弹出的位置,
                                                            showDuration:"300",//显示的时间
                                                            hideDuration:"1000",//消失的时间
                                                            timeOut:"2000",//停留的时间
                                                            extendedTimeOut:"1000",//控制时间
                                                            showEasing:"swing",//显示时的动画缓冲方式
                                                            hideEasing:"linear",//消失时的动画缓冲方式
                                                            iconClass: 'toast-info', // 自定义图标，有内置，如不需要则传空 支持layui内置图标/自定义iconfont类名
                                                            onclick: null, // 点击关闭回调
                                                        };

                                                        notice.success("删除成功！");
                                                    });



                                                    }


                                            }
                   });

                    });
                  } else if(menudata.id === 'edit_gruop'){

                       $.ajax({
                                   url:"/zgh0381/group_update/",
                                   type:"post",
                                    data:{"group_name":data.name,"desc":data.description,"group_id":data.id},
                                             beforeSend: function (xhr, settings) {
                                            xhr.setRequestHeader("X-CSRFToken", "{{ csrf_token }}");
                                          },
                                            success:function(result) {
                                                    if(result.res == 1){


                                                    }


                                            }
                   });





                      parent.layer.open({
                        type: 2
                        ,offset:'auto'
                        ,title:'更新组'
                        ,content:'/zgh0381/group_update/'
                        ,area:['1000px','600px']
                        ,btn:'关闭'
                        ,btnAlign:'c'
                        ,yes:function () {
                           parent.layer.closeAll();
                        }
                        ,end:function() {
                               location.reload();
                            }
                    });













                  }

                  else if (menudata.id === 'detail_user'){
                           $.ajax({
                                   url:"/zgh0381/user_dodetail/" + data.id,
                                   type:"GET",
                                             beforeSend: function (xhr, settings) {
                                            xhr.setRequestHeader("X-CSRFToken", "{{ csrf_token }}");
                                          },
                                            success:function(result) {
                                                    if(result.res == 1){


                                                    }


                                            }
                   });




                        parent.layer.open({
                        type: 2
                        ,offset:'auto'
                        ,title:'用户详细信息'
                        ,content:'/zgh0381/user_detail/'
                        ,area:['1000px','600px']
                        ,btn:'关闭'
                        ,btnAlign:'c'
                        ,yes:function () {
                           parent.layer.closeAll();
                        }
                        ,end:function() {
                               location.reload();
                            }
                    });






                  } else if (menudata.id === 'edit_user'){
                           $.ajax({
                                            url:"/zgh0381/edit_user/" ,
                                            type:"POST",
                                            data:{"user_name": data.name, "desc":data.description, "email":data.email,"user_id":data.id},
                                            dataType: "json",  // 返回的数据格式
                                            async: true,  // 异步的ajax
                                             beforeSend: function (xhr, settings) {
                                            xhr.setRequestHeader("X-CSRFToken", "{{ csrf_token }}");


                                            },
                                            success:function(result) {
                                                    if(result.res == 1){


                                                    }


                                            }
                   });




                        parent.layer.open({
                        type: 2
                        ,offset:'auto'
                        ,title:'编辑用户信息'
                        ,content:'/zgh0381/edit_user/'
                        ,area:['1000px','600px']
                        ,btn:'关闭'
                        ,btnAlign:'c'
                        ,yes:function () {
                           parent.layer.closeAll();
                        }
                        ,end:function() {
                               location.reload();
                            }
                    });






                  }else if (menudata.id === 'manage_group'){
                           $.ajax({
                                            url:"/zgh0381/manage_group/" ,
                                            type:"POST",
                                            data:{"group_name": data.name,"group_id":data.id},
                                            dataType: "json",  // 返回的数据格式
                                            async: true,  // 异步的ajax
                                             beforeSend: function (xhr, settings) {
                                            xhr.setRequestHeader("X-CSRFToken", "{{ csrf_token }}");


                                            },
                                            success:function(result) {
                                                    if(result.res == 1){


                                                    }


                                            }
                   });




                        parent.layer.open({
                        type: 2
                        ,offset:'auto'
                        ,title:'组管理'
                        ,content:'/zgh0381/manage_group/'
                        ,area:['1100px','600px']
                        ,btn:'关闭'
                        ,btnAlign:'c'
                        ,yes:function () {
                           parent.layer.closeAll();
                        }
                        ,end:function() {
                               location.reload();
                            }
                    });






                  }








                }
                ,align: 'right' //右对齐弹出（v2.6.8 新增）
                ,style: 'box-shadow: 1px 1px 10px rgb(0 0 0 / 12%);' //设置额外样式
              })
    }


        });


    });




    function doSearch() {
        //通过jquery获取参数的值
        var name=$("#name").val();
        var providername=$("#providername").val();
        var ispay=$("#ispay").val();

        table.reload('orderTable', {
            where: {
                name:name,
                providername:providername,
                ispay:ispay
            },page: {
                curr:1
            }
        });

    }


  layui.config({
        base: '/static/dist/'
    }).extend({
        notice: 'notice'
    });




</script>

</body>
</html>